package tour.board.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import board.util.Utilities;
import tour.board.to.Board;
import tour.board.to.CmBoard;
import tour.board.to.RecommendTO;
import tour.board.to.ReCmBoard;

@Repository
public class CmBoardDAOImpl implements CmBoardDAO{

	@Autowired
	private SqlMapClientTemplate sqlMap;
	
	
	public void setSqlMap(SqlMapClientTemplate sqlMap) {
		this.sqlMap = sqlMap;
	}


	@Override
	public Object insertContentForNewCount(CmBoard cmBoard) throws SQLException {
		return sqlMap.insert("cboard.insertContentForNewCount", cmBoard);
	}


	@Override
	public Object insertContentForReply(CmBoard cmBoard) throws SQLException {
		return sqlMap.insert("cboard.insertContentForReply", cmBoard);
	}


	@Override
	public ArrayList<CmBoard> selectBoardListByPage(int page)
			throws SQLException {
		HashMap map = new HashMap();
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("page", page);
		return (ArrayList<CmBoard>)sqlMap.queryForList("cboard.selectBoardListByPage", map);
	}


	@Override
	public ArrayList<CmBoard> selectBoardAllList() throws SQLException {
		return (ArrayList<CmBoard>)sqlMap.queryForList("cboard.selectBoardAllList");
	}


	@Override
	public int selectTotalContent() throws SQLException {
		return (Integer)sqlMap.queryForObject("cboard.selectTotalContent");
	}


	@Override
	public int updateViewCount(int no) throws SQLException {
		return sqlMap.update("cboard.updateViewCount", no);
	}


	@Override
	public CmBoard selectContentByNO(int no) throws SQLException {
		return (CmBoard)sqlMap.queryForObject("cboard.selectContentByNO", no);
	}


	@Override
	public int updateContent(CmBoard cmBoard) throws SQLException {
		return sqlMap.update("cboard.updateContent", cmBoard);
	}


	@Override
	public int deleteContentByNO(int no) throws SQLException {
		return sqlMap.delete("cboard.deleteContentByNO", no);
	}


	@Override
	public int updateRestep(int refamily, int restep) throws SQLException {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("refamily", refamily);
		map.put("restep", restep);
		return sqlMap.update("cboard.updateRestep", map);
	}


	@Override
	public ArrayList replyList() {
		return (ArrayList) sqlMap.queryForList("cboard.replyList");
	}


	@Override
	public void addReply(ReCmBoard reCmBoard) {
		sqlMap.insert("cboard.addReply", reCmBoard);
		
	}


	@Override
	public ArrayList getReplyByNo(int no) {
		return (ArrayList)sqlMap.queryForList("cboard.getReplyByNo",no);
	}
	
	//추천
	@Override
	public String recommend(RecommendTO rto) throws SQLException{
		return (String)sqlMap.queryForObject("cboard.recommend", rto);		
	}
	@Override
	public void updateCommendCount(int no) throws SQLException{
		sqlMap.update("cboard.updateCommendCount", no);
	}
	

	@Override
	public void insertRecommendInfo(RecommendTO rto) throws SQLException{
		sqlMap.insert("cboard.insertRecommendInfo", rto);		
	}


	@Override
	public ArrayList mainList() {
		return (ArrayList) sqlMap.queryForList("cboard.mainList");
	}


	@Override
	public ArrayList findTitle(String find) {
		return (ArrayList)sqlMap.queryForList("cboard.findTitle",find);
	}


	@Override
	public ArrayList findWriter(String find) {
		return (ArrayList)sqlMap.queryForList("cboard.findWriter",find);
	}

	

}
